package intranet.models;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class RegistrationModel {
	Connection DBConnection=null;
	public RegistrationModel(){
		DatabaseModel DBModel=new DatabaseModel();
		DBConnection=DBModel.GetConnection();
	}
	
public ResultSet SelectDepartment(){
	ResultSet rs=null;
	String sql="";
		try{
			Statement ConStatement=DBConnection.createStatement();
			sql="SELECT DEPARTMENT_ID,DEPARTMENT_NAME FROM DEPARTMENTS";
			rs=ConStatement.executeQuery(sql);
		}catch(Exception ex){ex.getLocalizedMessage();}
	return rs;
}	
public ResultSet SelectUser(){
	ResultSet rs=null;
	try{
		Statement ConStatement=DBConnection.createStatement();
		String sql="select USER_ID,USER_NAME FROM USER_ACCOUNTS";
		rs=ConStatement.executeQuery(sql);
	}catch(Exception ex){ex.getLocalizedMessage();}
return rs;
}
public ResultSet SelectReset(){
	ResultSet rs=null;
	try{
		Statement ConStatement=DBConnection.createStatement();
		String sql="select TEMPMAIL,NBC_email FROM USER_ACCOUNTS";
		rs=ConStatement.executeQuery(sql);
	}catch(Exception ex){ex.getLocalizedMessage();}
return rs;
}
public void AddUser(String fullname,String userid,String password,String mail,String dpt,String pwd){
	try{
		Statement ConStatement=DBConnection.createStatement();
		String sql="INSERT INTO USER_ACCOUNTS (USER_ID," +
											  "USER_NAME," +
											  "PASSWORD," +
											  "FULL_NAME," +
											  "NBC_EMAIL," +
											  "STATUE," +
											  "DATE_CREATE," +
											  "DEPARTMENT_ID," +
											  "TEMPMAIL) " +
											  "VALUES " +
				"(USER_ID.NEXTVAL," +
				"'"+userid+"'," +
			    "'"+password+"'," +
			    "'"+fullname+"'," +
			    "'"+mail+"'," +
			    "0," +
			    "SYSDATE," +
			    "'"+dpt+"'," +
			    "'"+pwd+"')";
		ConStatement.executeUpdate(sql);
		
		}catch(Exception ex){ex.getLocalizedMessage();}
}

public void Activation(String code,String to){
	try{
		Statement ConStatement=DBConnection.createStatement();
		String sql="UPDATE USER_ACCOUNTS SET ACTIVATION_CODE=" +
			    "'"+code+"',STATUE='1' WHERE NBC_EMAIL='"+to+"'";
		ConStatement.executeUpdate(sql);
		}catch(Exception ex){ex.getLocalizedMessage();}
}
public String Search(){
	String str=null;
	
	
	return str;
}
}
